'use strict';

/**
 * @description 用户表模型
 * */
module.exports = app => {
  const { STRING } = app.Sequelize;

  const User = app.model.define('user', {
    userName: {
      type: STRING(20),
      allowNull: false,
      comment: '用户昵称',
    },
    password: {
      type: STRING(64),
      allowNull: false,
      comment: '用户密码',
    },
    nickName: {
      type: STRING(20),
      allowNull: false,
      comment: '用户昵称',
    },
  });

  User.associate = () => {
    app.model.User.hasOne(app.model.UserInfo, {
      foreignKey: 'uid',
    });

    app.model.User.hasOne(app.model.UserAndRole, {
      foreignKey: 'uid',
    });
  };

  return User;
};
